<%@ page language="java" contentType="text/html; charset=utf-8"%>
<html>
<head>
<%@ include file="/extjs/include/all.jsp"%>
<link href="${pageContext.request.contextPath}/edu.ccut.saturn.authority.impl/userModule/page/css/authority.css" rel="stylesheet" type="text/css">
<title>机构列表</title>
</head>
<body>
</body>
</html>
<script>
var userName = '${__SATURN_AUTORITY_USER__.username}';
var userType = '${__SATURN_AUTORITY_USER__.usertype}';
var tempNodeId;
function refreshTree(nodeId){
	 tempNodeId = nodeId;
	 var tree = Ext.getCmp('dept-tree');
	 tree.root.reload();//让根节点重新加载
	/* tree.body.mask('部门加载中……', 'x-mask-loading');//给tree的body加上蒙版
	 tree.body.unmask();//全部展开之后让蒙版消失
	 tree.on('load', function(node, checked) {//树在Load时自动展开
				node.expand();          
				node.eachChild(function(child) {
					child.expand(); 
					//alert(child.id + "==" + tempNodeId);
					if(child.id==tempNodeId)  {//在这里判断是否与原来的NODE相等
						child.select();
						//alert(Ext.get(child.getUI().elNode).getY());
						//tree.body.scrollTo('top',Ext.get(child.getUI().elNode).getY());
						//tree.body.scrollTo('top',-200);
						//alert('scroll')
						return false;
						//alert('return');
			   } 
		});      
	 }, tree) */

	 document.getElementById('deptFrame').src = '';
}
Ext.onReady(function(){
	    function deptTreeClick(node) {		
			if(!(node.attributes.path)){
				node.attributes.path = '/edu.ccut.saturn.authority.impl::/departmentModule/action/QueryDeptByID.action?deptId='+node.id;
			} 
			link = "<%=request.getContextPath()%>" + node.attributes.path;
			Ext.get('deptFrame').dom.src = link;
		}
		
		var deptTree = new Ext.tree.TreePanel({
			id:'dept-tree',//设置一个id
			autoScroll:true,//自动出现滚动条
			containerScroll: true,//是否支持滚动条
			rootVisible:false,//是否显示跟节点
			loader:new Ext.tree.TreeLoader({
				dataUrl:'${pageContext.request.contextPath}/edu.ccut.saturn.authority.impl::/departmentModule/action/QueryDeptTree.action?username=' + userName + '&usertype=' + userType 
			})
		});
		//根节点
		
		var deptRootNode = new Ext.tree.AsyncTreeNode({
			text:'根节点',
			draggable:false,//是否可以拖拽
			id:'dept-tree-root'
		});
		deptTree.setRootNode(deptRootNode);
		
		deptTree.on('click', function(node) {
					deptTreeClick(node);
				},this);
			
		function loadDeptTree(deptName) {
				var loader = deptTree.getLoader();   
				deptTree.on('beforeload', function(){
            		loader.dataUrl = '${pageContext.request.contextPath}/edu.ccut.saturn.authority.impl::/departmentModule/action/QueryDeptTree.action?username=' + userName + '&usertype=' + userType + '&deptName=' + deptName     
				})
				deptTree.root.reload();//让根节点重新加载
				deptTree.root.expand(true,false,function(){
						deptTree.body.unmask();//全部展开之后让蒙版消失
				});
		}
			
		var queryDept = new Ext.form.FormPanel({
				  frame:true,
				  id:'queryDept',
				  title:'查询机构信息',
                  region:'north',
                  collapsible:true,
                  margins:'0 0 5 5',
                  height:100,
                  items:[{
	                   xtype:'textfield',
	                   fieldLabel: '机构名',
	                   labelWidth:75,
	                   name: 'DeptName',
	                   id:'DeptName',
	                   maxLength:20,
	                   vtype: 'isNumberAlphaUnderlineChinese',
	                   width:300
                  }],
			       buttons: [{
			           text: '查询',
			           handler:function(){
			           	if (queryDept.form.isValid()) {
			           	
							loadDeptTree(Ext.get('DeptName').getValue());
							
			      			} else {
			      			
			      				Ext.MessageBox.alert('警告','对不起,您的页面输入有误');
			      			}
			           }
			       }]
       });

		var viewport = new Ext.Viewport({
			layout:'border',		
			items:[	
				//queryDept,
				{	
					region:'west',
					title:'机构列表',
					collapsible:true,
					split:true,
					width:225,
					minSize:175,
					maxSize:400,
					layout:'fit',
					margins:'0 0 0 5',
					items:deptTree
				}, new Ext.Panel({
					id:'deptMain',
					title:'机构基本信息',
                    region:'center',
                    html:'<iframe id="deptFrame" name="deptFrame" width="100%" marginwidth="0" height="100%" marginheight="0" scrolling="auto" frameborder="0"></iframe>'
                })
			]
		});	
});
</script>